package org.goldenport.g3

import scala.collection.mutable.{LinkedHashMap}

/**
 * @since   Apr. 25, 2010
 * @version May.  5, 2010
 * @author  ASAMI, Tomoharu
 **/
class G3MessageStore {
  private val all_post_parcels = new LinkedHashMap[G3ParcelId, G3Parcel]
  private val job_result_parcels = new LinkedHashMap[G3JobId, G3Parcel]
  private val transaction_result_parcels = new LinkedHashMap[G3TransactionId, G3Parcel]
  private val unitofwork_result_parcels = new LinkedHashMap[G3UnitofworkId, G3Parcel]

  def post(parcel: G3Parcel) {
    all_post_parcels += parcel.id -> parcel
  }

  def setUnitofworkResult(uow: G3UnitofworkId, parcel: G3Parcel) {
    assume(!unitofwork_result_parcels.contains(uow))
    unitofwork_result_parcels += uow -> parcel
  }

  def getResultParcel(ticket: G3Ticket): Option[G3Parcel] = {
    ticket.unitofwork.map(uow => unitofwork_result_parcels(uow))
  }
}
